<?php
namespace app\examScore\controller;
use app\common\Base;
use think\Db;
//--培优总分公式配置
class AdvancedTotalFormula extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$examId = input("examId");
		$classType = input("clazzType");
		$where = [];
		if($examId) $where["考试ID"] = $examId;
		if($classType != null) $where["班级层次"] = $classType;
		$result = Db::table("培优总分公式")->alias("a")
				->join("年级名称 b","a.年级ID=b.ID","LEFT")
				->join("考试名称 c","a.考试ID=c.ID","LEFT")
				->field("a.ID,考试ID,年级名称+考试名称 考试名称,a.年级ID,年级名称,班级层次,培优分段,公式")
				->where($where)
				->order("考试ID desc,年级ID,班级层次")
				->select();
		$grid['rows'] = selectResult($result);
		$grid['total'] = count($result);
		return $grid;
	}
	
	public function addUpdate() {
		$all = request()->param();
		try {
			if(array_key_exists("ID", $all)) {
				update('培优总分公式', $all);
			} else {
				insert('培优总分公式', $all);
			}
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

	public function del() {
		$delIds = input("delIds");
		try {
			Db::name('培优总分公式')->where('ID','in',explode(",", $delIds))->delete();
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

}
